import{_ as e}from"./plugin-vue_export-helper-DlAUqK2U.js";import{o as n,c as t,f as i}from"./app-CRsXJvQX.js";const a={},l=i(`<p>提货单模式</p><p>异步返回</p><div class="language-text line-numbers-mode" data-ext="text" data-title="text"><pre class="language-text"><code>//接口
public interface Data{
  String getContent();
}

//FutureData提货单
public class FutureData implement Data{

private volatile ready = false;
private Data realData ;

public synchrionized void setRealData(Data data){
  this.realData = data;
  this.ready = true;  
  notifyAll();
}

public String getContent(){
  while(!ready){
    wait();
  }
  return realData.getContent();
}

}

//RealData 耗时交易

public class RealData implement Data{
  private String content;

  public void execute(){
    sleep(10);
    content = &quot;耗时交易10s&quot;;
  }

  public String getContent(){
    return content;
  }
}

</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>调用</p><div class="language-text line-numbers-mode" data-ext="text" data-title="text"><pre class="language-text"><code>main(){

  FutureData futureData = new FutureData();
  new Thread(){
  
  public void run(){
    RealData  realData = new RealData();
    //耗时交易
    realData.execute();
    futureData.setRealData(realData);
  }  

  }

  printf(&quot;打印&quot;+ futureData.getContent());

}

</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>juc</p><p>Callable接口 Runable有返回值</p><p>Future FutureTask</p>`,8),r=[l];function s(d,u){return n(),t("div",null,r)}const m=e(a,[["render",s],["__file","Future模式.html.vue"]]),o=JSON.parse('{"path":"/basis/juc/java%E9%AB%98%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/Future%E6%A8%A1%E5%BC%8F.html","title":"Future模式","lang":"zh-CN","frontmatter":{"title":"Future模式","date":"2024-03-24T11:47:50.000Z","category":["java高并发编程"],"tag":["archive"],"description":"提货单模式 异步返回 调用 juc Callable接口 Runable有返回值 Future FutureTask","head":[["meta",{"property":"og:url","content":"https://yinlingchaoliu.github.io/basis/juc/java%E9%AB%98%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/Future%E6%A8%A1%E5%BC%8F.html"}],["meta",{"property":"og:site_name","content":"引领潮流"}],["meta",{"property":"og:title","content":"Future模式"}],["meta",{"property":"og:description","content":"提货单模式 异步返回 调用 juc Callable接口 Runable有返回值 Future FutureTask"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2024-03-25T14:17:18.000Z"}],["meta",{"property":"article:author","content":"引领潮流"}],["meta",{"property":"article:tag","content":"archive"}],["meta",{"property":"article:published_time","content":"2024-03-24T11:47:50.000Z"}],["meta",{"property":"article:modified_time","content":"2024-03-25T14:17:18.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"Future模式\\",\\"image\\":[\\"\\"],\\"datePublished\\":\\"2024-03-24T11:47:50.000Z\\",\\"dateModified\\":\\"2024-03-25T14:17:18.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"引领潮流\\",\\"url\\":\\"https://www.jianshu.com/u/bdcce32c05dd\\"}]}"]]},"headers":[],"git":{"createdTime":1711376238000,"updatedTime":1711376238000,"contributors":[{"name":"引领潮流","email":"heat13@qq.com","commits":1}]},"readingTime":{"minutes":0.47,"words":140},"filePathRelative":"basis/juc/java高并发编程/Future模式.md","localizedDate":"2024年3月24日","excerpt":"<p>提货单模式</p>\\n<p>异步返回</p>\\n<div class=\\"language-text\\" data-ext=\\"text\\" data-title=\\"text\\"><pre class=\\"language-text\\"><code>//接口\\npublic interface Data{\\n  String getContent();\\n}\\n\\n//FutureData提货单\\npublic class FutureData implement Data{\\n\\nprivate volatile ready = false;\\nprivate Data realData ;\\n\\npublic synchrionized void setRealData(Data data){\\n  this.realData = data;\\n  this.ready = true;  \\n  notifyAll();\\n}\\n\\npublic String getContent(){\\n  while(!ready){\\n    wait();\\n  }\\n  return realData.getContent();\\n}\\n\\n}\\n\\n//RealData 耗时交易\\n\\npublic class RealData implement Data{\\n  private String content;\\n\\n  public void execute(){\\n    sleep(10);\\n    content = \\"耗时交易10s\\";\\n  }\\n\\n  public String getContent(){\\n    return content;\\n  }\\n}\\n\\n</code></pre></div>","autoDesc":true}');export{m as comp,o as data};
